 <?php


Class Index_LoginView Extends Yapary_MVC_View
{
	const NEWLINE = "\n";


    public function defaultView (array $arrVar)
    {
    	$showLoginDialog = false;
    	$output		= '';

    	// Auszugebende Daten im entsprechenden Registry-Eintrag speichern
    	$registry = Yapary_SingletonRegistry::getInstance();

    	/* @var $oSql Yapary_Db_Sql_Connector */
    	$oSql = $registry->oSql;
    	/* @var $model Index_IndexModel */
    	$model = $this->model; // Durch @var-Definition Eclipse Autocomplete nutzen!
    	/* @var $oHeader Yapary_Header_Header */
    	$oHeader = $registry->oHeader;
    	/* @var $oMetaTag Yapary_Header_MetaTag */
    	$oMetaTag = $registry->oMetaTag;
    	/* @var $oMainMenu Yapary_Menu_XmlMenu */
    	$oMainMenu = $registry->oMainMenu;
    	/* @var $oFooterMenu Yapary_Menu_XmlMenu */
    	$oFooterMenu = $registry->oFooterMenu;
    	/* @var $oXmlTranslator Yapary_Translation_XmlTranslator */
    	$oXmlTranslator = $registry->oXmlTranslator;

    	/* @var $oManager UserManager */
    	$oManager = new UserManager();


    	// Content
    	if ($model->doWhat == "login") {
    		//echo var_dump($oManager->checkPassGetUser($model->username, $model->password));
    		if($oManager->checkPassGetUser($model->username, $model->password) != NULL) {
    			$loginRes = $oManager->loginUserByDb($model->username, $model->password);
    			if ($loginRes == 1) {
	    			$_SESSION['status'] = "loggedIn";
	    			$_SESSION['username'] = $model->username;

	    			$output .= $oXmlTranslator->get('LOGIN_SUCCESS');
	    			$oMetaTag->setRefresh(BASEURL.'account', 1);
    			} else {
	    			$output .= $oXmlTranslator->get('LOGIN_FAILED', array('VAR' => $loginRes));
    			}
    		} else {
    			$output .= $oXmlTranslator->get('LOGIN_FAILED', array('VAR' => 'User/Password'));
    		}
    	} else if ($model->doWhat == "logout"){
    		if($oManager->logoutUserbyDb(@$_SESSION['username']) >= 0) {
    			$_SESSION['status'] = "loggedOut";
    			$_SESSION['username'] = "";

    			$output .= $oXmlTranslator->get('LOGOUT_SUCCESS');
    			$oMetaTag->setRefresh(BASEURL, 1);
    		} else {
    			$output .= $oXmlTranslator->get('LOGOUT_FAILED');
    		}
    	}

    	// HTML Head Title
    	$oHeader->setTitle('Login');

    	// MainMenu
		$oMainMenu->expand('ACCOUNT_INDEX');
		$oMainMenu->setSelected(strtoupper(Yapary_SingletonRegistry::getInstance()->routeName));
		$oMainMenu->addAfter('BASKET', 'INSTALL_INDEX', 'install.php', 'Install/uninstall');

		// FooterMenu
		$oFooterMenu->setSelected(strtoupper(Yapary_SingletonRegistry::getInstance()->routeName));

		// Daten in globaler Registry speichern, um diese in "layout.phtml" ausgeben zu koennen
		$registry->header		= $this->partial->insert('headerData.phtml');
		$registry->mainMenu		= $oMainMenu->display(strtoupper(Yapary_SingletonRegistry::getInstance()->routeName));

		$registry->content		= $this->partial->insert('contentData.phtml', array('content_mid' => $output));
    	$registry->footerMenu	= $oFooterMenu->display();
    }

}

?>